<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of WriteOff
 *
 * @author Administrator
 */
class PackegeList extends WMS_Controller
{

    var $whsCode;
    var $user_data;

    function __construct()
    {
        parent::__construct();
        $gp = gp();
        $this->user_data = $this->session->userdata('users');
        $this->whsCode = $userData['user_main_whs_code'];
        //加载模型
        $this->load->service('wms/part_write_off_service');
        $this->load->service('wms/package_service');
        $this->load->service('wms/api_service');
        $this->load->service('wms/time_service');
        $this->load->service('wms/sap_service');
        header("Content-type: text/html; charset=utf-8");
    }

    function get_panel_type($type)
    {
        $panel_type = '';
        if (MD5('overseas' . date("d")) == $type)
        {
            $panel_type = 'overseas';
        }
        elseif (MD5('china' . date("d")) == $type)
        {
            $panel_type = 'china';
        }
        else
        {
            js_goto(getenv("HTTP_REFERER"),lang('wms_tips_20016') );
            exit;
        }
        return $panel_type;
    }

    public function overseas()
    {
        //锁死仓库
        $whs = $this->whsCode;
        $wherein = array('whs_code' => $whs);
        $where = array(
        );
        $gp = gp();
        $package_id = $gp['package_id'] ? $gp['package_id'] : '';
        $page = $gp['page'] ? intval($gp['page']) : 1;
        //
        $str = '?';
        $page_size = 15;
        if ('' != $package_id)
        {
            $where['package_id'] = $package_id;
            $str .= 'package_id=' . $package_id;
        }
        //
        //分页查询
        $this->load->library('pagination');
        $config['page_query_string'] = TRUE;
        $config['base_url'] = blang_url('wms/PackegeList/overseas' . $str);
        $data['type'] = 'overseas';
        $config['total_rows'] = $this->package_service->get_list_count($where, $wherein, $like);
        $config['uri_segment'] = config_item('enable_lang') ? 5 : 4;
        $config['per_page'] = $page_size;
        $this->pagination->initialize($config);
        $data['pageShow'] = $this->pagination->create_links();
        //分页结束
        //获取产品库存列表
        $receivingList = $this->package_service->get_list_page(($page - 1) * $page_size, $page_size, $orderstr, $where, $wherein, $like);
        $data['receivingList'] = $this->api_service->fields_erp_product_info($receivingList);
        $data['receivingList'] = $this->time_service->show_time($data['receivingList'], 'created_time');
        $this->load->view('defaults/wms/package_list', $data);
        $this->load->view('defaults/common/footer', $data);
    }

    public function china()
    {
        //锁死仓库
        $whs = $this->whsCode;
        $wherein = array('whs_code' => $whs);
        $where = array(
        );
        $gp = gp();
        $package_id = $gp['package_id'] ? $gp['package_id'] : '';
        $page = $gp['page'] ? intval($gp['page']) : 1;
        //
        $str = '?';
        $page_size = 15;
        if ('' != $package_id)
        {
            $where['package_id'] = $package_id;
            $str .= '&package_id='.$package_id;
        }
        //
        //分页查询
        $this->load->library('pagination');
        $config['page_query_string'] = TRUE;
        $config['base_url'] = blang_url('wms/PackegeList/china' . $str);
        $data['type'] = 'china';
        $config['total_rows'] = $this->package_service->get_list_count($where, $wherein, $like);
        $config['uri_segment'] = config_item('enable_lang') ? 5 : 4;
        $config['per_page'] = $page_size;
        $this->pagination->initialize($config);
        $data['pageShow'] = $this->pagination->create_links();
        //分页结束
        //获取产品库存列表
        $receivingList = $this->package_service->get_list_page(($page - 1) * $page_size, $page_size, $orderstr, $where, $wherein, $like);
        $data['receivingList'] = $this->api_service->fields_erp_product_info($receivingList);
        $data['receivingList'] = $this->time_service->show_time($data['receivingList'], 'created_time');
        $this->load->view('defaults/wms/package_list', $data);
        $this->load->view('defaults/common/footer', $data);
    }

    function detail($package_id='', $type='')
    {
        if ('' == $type)
        {
            $type = md5('overseas' . date("d"));
        }
        $panel_type = $this->get_panel_type($type);
        $data = $this->package_service->get_with_items($package_id);
        $data = $this->time_service->show_time($data, 'created_time');
        $data['status_view'] = $this->package_service->get_status();
        $data['panel_type'] = $panel_type;
        $this->load->view('defaults/wms/package_panel', $data);
        $this->load->view('defaults/common/footer');
    }

    function shipped($param)
    {
        $param_array = explode("_", $param);
        $package_id = $param_array[0];
        $track_id = $param_array[1];
        $from_panel_type = $param_array[2];
        $panel_type = $this->get_panel_type($from_panel_type);
        $isupdate = $this->package_service->shipped_with_track($package_id, $track_id);
        if ($isupdate)
        {
            $this->detail($package_id, $from_panel_type);
        }
        else
        {
            js_goto(getenv("HTTP_REFERER"),lang('wms_tips_20016') );
        }
    }

    function receive_package_product($type)
    {
        $gp = gp();
        $package_prodcut_id = $gp['package_product_id'];
        $qty = $gp['qty'];
        $package_id = $gp['package_id'];
        $panel_type = $this->get_panel_type($type);
        $isupdate = $this->package_service->receive_package_product($package_prodcut_id, $qty);
        if ($isupdate)
        {
            $this->detail($package_id, $type);
        }
        else
        {
            js_goto(getenv("HTTP_REFERER"),lang('wms_tips_20016') );
        }
    }

    function receive_clean($param)
    {
        $param_array = explode("_", $param);
        $package_id = $param_array[0];
        $from_panel_type = $param_array[1];
        $panel_type = $this->get_panel_type($from_panel_type);
        $isupdate = $this->package_service->receive_clean($package_id);
        if ($isupdate)
        {
            $this->detail($package_id, $from_panel_type);
        }
        else
        {
            js_goto(getenv("HTTP_REFERER"),lang('wms_tips_20016') );
        }
    }

}

?>
